import { axiosPost } from './axiosFun.js'

//获取当天信息
const getDayData = date => {
	return new Promise((resolve,reject) => {
		axiosPost({
			url: '/api/calendar/day',
			data: {
				date
			},
			success:function(data){
				resolve(data)
				// console.log('1111')
			},
			error:function(err){
				reject(err)
			}
		})
	})
}

//获取近期假期
const getMonthData = yearMonth => {
	return new Promise((resolve,reject) => {
		axiosPost({
			url: '/api/calendar/month',
			data: {
				'year-month':yearMonth
			},
			success:function(data){
				resolve(data)
			},
			error:function(err){
				reject(err)
			}
		})
	})
}

//获取当年假期
const getYearData = year => {
	return new Promise((resolve,reject) => {
		axiosPost({
			url: '/api/calendar/month',
			data: {
				year
			},
			success:function(data){
				resolve(data)
			},
			error:function(err){
				reject(err)
			}
		})
	})
}

//综合方法

const getData = async (field,date,daydetail) => {
	let data = null
	switch(field){
		case 'day':
			data = await getDayData(date)
			break
		case 'month':
			data = await getMonthData(date)
			break
		case 'year':
			data = await getYearData(date)
			break
	}
	// console.log('4444')
	// daydetail = data
	// console.log(data)

}

export{
	getDayData,
	getMonthData,
	getYearData,
	getData
}
